/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gs.gms.messanger.ui.core;

import com.gs.gms.model.dto.UserDto;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import com.gs.gms.messanger.ui.GMSMessengerConstants;
/**
 *
 * @author Sabuj
 */
public class UserConnectionCellRenderer implements ListCellRenderer<UserDto> {

    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
    
    @Override
    public Component getListCellRendererComponent(
            JList<? extends UserDto> list, UserDto value, 
            int index, boolean isSelected, boolean cellHasFocus) {
        
        JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(
                list, value, index, isSelected, cellHasFocus);
        if(null != value.getCurrentSession()){
            if(value.getCurrentSession().isActive()){
                renderer.setIcon(GMSMessengerConstants.STATUS_ICON_ACTIVE);
            } else {
                renderer.setIcon(GMSMessengerConstants.STATUS_ICON_AWAY);
            }
        } else {
            renderer.setIcon(GMSMessengerConstants.STATUS_ICON_OFFLINE);
        }
        renderer.setText(value.getDisplayName());
        
        return renderer;
    }

}
